/**
 * ajax 服务路由集合
 */
const router = require('koa-router')({
    prefix: '/app' //定义路由前缀
})
const controllers = require('../controllers/index')

// 从 sdk 中取出中间件
// 这里展示如何使用 Koa 中间件完成登录态的颁发与验证
const { auth: { authorizationMiddleware, validationMiddleware } } = require('../qcloud')

// --- 登录与授权 Demo --- //
// 登录接口
router.get('/login', authorizationMiddleware, controllers.login)
// 用户信息接口（可以用来验证登录态）
router.get('/user', validationMiddleware, controllers.user)



// --- 图片上传 Demo --- //
// 图片上传接口，小程序端可以直接将 url 填入 wx.uploadFile 中
router.post('/upload', controllers.upload)

// --- 信道服务接口 Demo --- //
// GET  用来响应请求信道地址的
router.get('/tunnel', controllers.tunnel.get)
// POST 用来处理信道传递过来的消息
router.post('/tunnel', controllers.tunnel.post)

// --- 客服消息接口 Demo --- //
// GET  用来响应小程序后台配置时发送的验证请求
router.get('/message', controllers.message.get)
// router.get('/getmark', controllers.record.getmark)
// POST 用来处理微信转发过来的客服消息
router.post('/message', controllers.message.post)


// 首页相关的接口
router.get('/index/index', controllers.Index.index)
router.post('/user/userInfo', controllers.userinfo.index.userInfo)
router.get('/user/getId', controllers.userinfo.index.getId)
// 分类相关的接口
router.get('/category/categoryNav', controllers.category.index.categoryNav)
router.get('/category/headData', controllers.category.index.headData)
router.get('/category/childData', controllers.category.index.childData)
router.get('/category/infoData', controllers.category.index.infoData)

// 搜索相关的接口
router.get('/search/indexaction', controllers.search.index.indexAction)
router.post('/search/addhistoryaction', controllers.search.index.addHistoryAction) //
router.post('/search/clearhistoryAction', controllers.search.index.clearHistoryAction) // 清除搜索历史
router.get('/search/helperaction', controllers.search.index.helperAction) // 搜索提示

// // 商品详情
router.get('/goods/detailaction', controllers.goods.index.detailAction)
router.get('/goods/goodsList', controllers.goods.index.goodsList)

// // 收藏相关的接口
router.post('/collect/addcollect', controllers.collect.index.addCollect)
router.get('/collect/collectList', controllers.collect.index.collectList)
router.post('/collect/delCollect', controllers.collect.index.delCollect)



// // 订单相关的接口
router.get('/order/buyAction', controllers.order.index.buyAction)
router.post('/order/submitAction', controllers.order.index.submitAction)
router.get('/order/detailAction', controllers.order.index.detailAction)
router.post('/order/orderDetail', controllers.order.index.orderDetail)
// router.post('/order/orderGoods', controllers.order.index.orderGoods)
// 获取历史订单
router.get('/order/myOrder', controllers.order.index.myOrder)


// // 购物车相关的接口
router.post('/cart/addCart', controllers.cart.index.addCart)
router.get('/cart/cartList', controllers.cart.index.cartList)
router.post('/cart/delCart', controllers.cart.index.delCart)
router.post('/cart/cartNumber', controllers.cart.index.cartNumber)


// // 收货地址相关的接口
router.get('/address/getListAction', controllers.address.index.getListAction)
router.get('/address/detailAction', controllers.address.index.detailAction)
router.post('/address/saveAction', controllers.address.index.saveAction)
router.post('/address/delAdress', controllers.address.index.delAdress)

module.exports = router
